package ysq.xyg.web.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.util.BaseConstant;

import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.web.model.po.WebMember;
import ysq.xyg.web.model.vo.WebMemberVo;
import ysq.xyg.web.service.WebMemberService;

import javax.annotation.Resource;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.servlet.http.HttpServletRequest;

/**
 * 业务模块-会员controller层
 *
 * @author shengQiang yu
 * @date 2019-4-26 13:51:56
 */
@RestController
public class WebMemberController extends BaseController {

    private static Logger log= LoggerFactory.getLogger(WebMemberController.class);
    @Resource
    private WebMemberService webMemberService;
   /* @Resource
    private JmsTemplate jmsTemplate;
    @Autowired
    @Qualifier("queueDestination")
    private Destination destination;*/

    private WebMember webMember;


   /* @RequestMapping(value = "/webMember/sendMessageMq")
    public ReturnEntity sendMessageMq(String num){
        sendMessage(destination,"信息"+num);
        return new ReturnEntity();
    }

    public void sendMessage(Destination destination,  final String message) {
        jmsTemplate.send(destination, new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                return session.createTextMessage(message);
            }
        });
    }*/
    /**
     * 分页查询
     *
     * @param webMemberVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author shengQiang yu
     * @date 2019-4-26 13:51:56
     */
    @BaseLog(module = "业务模块",className = "会员",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webMember/page",method = RequestMethod.POST)
    public ReturnEntity page(WebMemberVo webMemberVo, int pageSize, int pageNum){
        ReturnEntity returnEntity = webMemberService.page(webMemberVo,pageSize,pageNum);
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-4-26 13:51:56
     */
    @RequestMapping(value = "/webMember/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id){
        ModelAndView view = new ModelAndView("/web/webMemberUpdateOrSave");
        if(StrUtil.isNotEmpty(id)){
            webMember = webMemberService.selectByPrimaryKey(id);
            view.addObject("webMember", webMember);
        }
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-4-26 13:51:56
     */
    @BaseLog(module = "业务模块",className = "会员",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webMember/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return webMemberService.delete(id,acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param webMemberVo Vo对象
     * @author shengQiang yu
     * @date 2019-4-26 13:51:56
     */
    @BaseLog(module = "业务模块",className = "会员",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webMember/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request,WebMemberVo webMemberVo){
        return webMemberService.addOrUpdate(webMemberVo,acceptCurrentUser(request));
    }
}